package com.youmingxing.adpter.selfInfo;


import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.youmingxing.R;
import com.youmingxing.activity.selfInfo.PersonalInfoActivity;
import com.youmingxing.bean.selfinfo.FansOrFocus;
import com.youmingxing.utils.ViewHolderUtils;

import java.util.List;

import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * 我的粉丝
 */
public class MyFansTopAdapter extends BaseAdapter {
    private List<FansOrFocus> mList;
    private TextView nameTv;
    private TextView rankingnumTv;
    private TextView ticketnumTv;
    private ImageView icon;

    private Context context;


    public MyFansTopAdapter(Context mContext,List<FansOrFocus> list) {
        this.context = mContext;
        mList = list;

    }


    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        if ((null != mList && mList.size() > 0) && (position >= 0 && position < mList.size())) {
            return mList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.activity_myfans_top_griditem, null);
        }
        nameTv = ViewHolderUtils.getViewHolderView(convertView, R.id.name1);
        rankingnumTv = ViewHolderUtils.getViewHolderView(convertView, R.id.topranking);
        ticketnumTv = ViewHolderUtils.getViewHolderView(convertView, R.id.tickets_num1);

        icon = ViewHolderUtils.getViewHolderView(convertView, R.id.head_icon1);

        FansOrFocus fan = mList.get(position);
        nameTv.setText(fan.nickname);
        ticketnumTv.setText(fan.votenum + "");
        Glide.with(context).load(fan.headimg)
                .placeholder(R.drawable.default_avatar).error(R.drawable.default_avatar)
                .bitmapTransform(new CropCircleTransformation(
                        context)).crossFade().into
                (icon);
        if (position == 0) {
            rankingnumTv.setText("TOP1");
//            rankingnumTv.setBackgroundResource(R.drawable.roundconner_yellow);
//            rankingnumTv.setTextColor(Color.parseColor("#fdfdfd"));
        } else if (position == 1) {
            rankingnumTv.setText("TOP2");
//            rankingnumTv.setTextColor(Color.parseColor("#fdfdfd"));
//            rankingnumTv.setBackgroundResource(R.drawable.roundconner_yellow);
        } else if (position == 2) {
            rankingnumTv.setText("TOP3");
//            rankingnumTv.setTextColor(Color.parseColor("#fdfdfd"));
//            rankingnumTv.setBackgroundResource(R.drawable.roundconner_yellow);
//        } else if (position == 3) {
//            rankingnumTv.setText("TOP4");
//            rankingnumTv.setTextColor(Color.parseColor("#EA4141"));
//            rankingnumTv.setBackgroundResource(R.drawable.roundconner_rededge);
        }

        icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PersonalInfoActivity.class);
                intent.putExtra("u_id", mList.get(position).id);
                context.startActivity(intent);
            }
        });
        return convertView;
    }
}